﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// add
using System.IO;


namespace FormBase
{
    public partial class FPGM0080 : Form
    {
        public FPGM0080()
        {
            InitializeComponent();
        }

        private void btnDefaultRS232_Click(object sender, EventArgs e)
        {
            myDefault();
        }
        private void myDefault()
        {
            txtRoot.Text = @"c:\Temp\TestFileSys\";
            txtFileNo.Text = "12345";
            txtFileDescription.Text = "This is a test for testing FIS (File Index System)";
 
        }

        private void FPGM0080_Load(object sender, EventArgs e)
        {
            Text = "Upload file to file system";

            myDefault();

        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            StringBuilder sb1 = new StringBuilder();

            sb1.Length = 0;
            long l1 = 0;
            if (long.TryParse(txtFileNo.Text, out l1))
            {
                string s1 = txtRoot.Text + CCommon.gGetPhysicalFilename(l1);
                string sPath = Path.GetDirectoryName(s1);
                string sFile = Path.GetFileName(s1);
                string sFullname = Path.GetFullPath(s1);

                sb1.AppendLine("File No. = " + l1.ToString());
                sb1.AppendLine("File = " + txtUploadFilename.Text);
                sb1.AppendLine("Description = " + txtFileDescription.Text);
                sb1.AppendLine("File Index    = " + s1 + ".txt");
                sb1.AppendLine("File position = " + sPath + "\\" + txtUploadFilename.Text);
                sb1.AppendLine("File upload = " + txtUploadFullname.Text);

                sb1.AppendLine("Contents in " + s1 + ".txt");
                sb1.AppendLine(l1.ToString());
                sb1.AppendLine(txtUploadFilename.Text);
                sb1.AppendLine(txtFileDescription.Text);
                sb1.AppendLine(s1 + ".txt");
                sb1.AppendLine(sPath + "\\" + txtUploadFilename.Text);
                sb1.AppendLine(txtUploadFullname.Text);


                txtMsg.Text = sb1.ToString();
            }
            else
                txtMsg.Text = "Please input long no.";

        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog1 = new OpenFileDialog();

            //dialog1.InitialDirectory = txtRoot.Text;
            dialog1.InitialDirectory = @"c:\Temp\";
            //dialog1.InitialDirectory = Path.GetFullPath(mProject.msFilenameCFG);
                    //openFileDialog.InitialDirectory = mProject.msPathLastWork;
                    //openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            //openFileDialog.Filter = "Config Setup Files(*.cfg)|*.cfg|All Files (*.*)|*.*";
            dialog1.Filter = "All Files (*.*)|*.*";
            if (dialog1.ShowDialog(this) == DialogResult.OK)
            {
                txtUploadPath.Text = dialog1.InitialDirectory;
                txtUploadFullname.Text = dialog1.FileName;
                txtUploadFilename.Text = Path.GetFileName(txtUploadFullname.Text);
                txtUploadExtName.Text = Path.GetExtension(txtUploadFullname.Text);
            }

        }
    }
}
